package com.laotang.第_1_章_数组和字符串.力扣_228_汇总区间;

import java.util.ArrayList;
import java.util.List;

public class _228_summary_ranges {
    public List<String> summaryRanges(int[] nums) {
        int n = nums.length;
        List<String> res = new ArrayList<>();
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (i == n - 1 || nums[i + 1] - nums[i] != 1) {
                StringBuilder sb = new StringBuilder();
                sb.append(nums[j]);
                if (j != i) {
                    sb.append("->");
                    sb.append(nums[i]);
                }
                res.add(sb.toString());
                j = i + 1;
            }
        }
        return res;
    }
}
